using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class RegularExpressionValidatorByCodePage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label label = new Label();
        label.Text = "Your phone:";
        this.form1.Controls.Add(label);
        TextBox textBox = new TextBox();
        textBox.ID = "Phone";
        this.form1.Controls.Add(textBox);
        Button button = new Button();
        button.Text = "OK";
        this.form1.Controls.Add(button);
        RegularExpressionValidator regularExpressionValidator = new RegularExpressionValidator();
        regularExpressionValidator.ControlToValidate = textBox.ID;
        regularExpressionValidator.ValidationExpression = @"((\(\d{3}\)?)|(\d{3}-))?\d{3}-\d{4}";
        regularExpressionValidator.Text="Invalid phone number";
        this.form1.Controls.Add(regularExpressionValidator);
    }
}
